<!-- 多个日期 -->
<template>
    <block>
      <van-field
        :value="form[name]"
        :required="!norequired" 
        clickable
        :label="label"
        :placeholder="placeholder"
        readonly
        is-link
        @click-input="dateShow = true"
      ></van-field>
      <van-calendar
        :show="dateShow"
        @close="onDateClose"
        @confirm="onDateConfirm"
        :minDate="minDate"
        type="multiple"
      />
    </block>
  </template>
  <script>
  export default {
    data() {
      return {
          dateShow:false,
          minDate: new Date(2020, 0, 1).getTime(),
      };
    },
    props:{
      form:Object, //需要修改的数据
      label:String,
      placeholder:String,
      name:String,
      norequired:Boolean,  // 默认是false 不影响其他的 这个
    },
    methods:{
      formatDate(date) {
        date = new Date(date);
        return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`;
      },
      changeDate() {
        this.dateShow = true;
      },
      onDateConfirm(date) {
  
        // this.form.expected_date = this.formatDate(date.detail);
        this.form.start_time = this.formatDate(date.detail[0]); //开始时间
        this.form.end_time = this.formatDate(date.detail[1]); //结束时间
       
        console.log(date,'date');
        this.$emit("click-input", this.name,[this.form.start_time,this.form.end_time]);
        this.dateShow = false;
      },
      onDateClose() {
        this.dateShow = false;
      },
    }
  };
  </script>